package dm.ast.model.gen;

import dm.ast.DmASTNode;
import dm.ast.DmRowLimit;
import test.utility.Randomly;

import java.util.Random;

/**
 * 根据模板AST生成Limit子句
 */
public class RowLimitGen extends ASTGenBase{

    static int RowLimitmax = 150;
    @Override
    public DmASTNode gen(int astLevel, int wid_t, int dep_t) {
        DmRowLimit rowLimit = new DmRowLimit();
        int limitFormat = (int) Randomly.getNotCachedInteger(0 , DmRowLimit.SUPPORT_FORMAT);
        rowLimit.setFormat(limitFormat);

        rowLimit.setOffsetNum(String.valueOf((int)Randomly.getNotCachedInteger(1, RowLimitmax)));
        if(Randomly.getBooleanWithSmallProbability()){
            rowLimit.setOffsetNum("NULL");
        }

        rowLimit.setFetchNum(String.valueOf((int)Randomly.getNotCachedInteger(1,RowLimitmax)));
        if(Randomly.getBooleanWithSmallProbability()){
            rowLimit.setFetchNum("NULL");
        }

        rowLimit.setFlags((int)Randomly.getNotCachedInteger(0 , 2<<DmRowLimit.FLAGS_CNT));
        rowLimit.setWidt();
        rowLimit.setDept();

        return rowLimit;
    }
}
